package com.ruoyi.report_hntjg.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.report_hntjg.domain.bo.ReportHntjgHntqdhtfjlbBaDetailBo;
import com.ruoyi.report_hntjg.mapper.ReportHntjgHntqdhtfjlbBaDetailMapper;
import com.ruoyi.report_hntjg.service.IReportHntjgHntqdhtfjlbBaDetailService;
import com.ruoyi.report_hntjg.domain.ReportHntjgHntqdhtfjlbBaDetail;
import com.ruoyi.report_hntjg.domain.vo.ReportHntjgHntqdhtfjlbBaDetailVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 混凝土强度试验检测记录（回弹法）-详情Service业务层处理
 *
 * @author tll
 * @date 2024-08-07
 */
@RequiredArgsConstructor
@Service
public class ReportHntjgHntqdhtfjlbBaDetailServiceImpl implements IReportHntjgHntqdhtfjlbBaDetailService {

    private final ReportHntjgHntqdhtfjlbBaDetailMapper baseMapper;

    /**
     * 查询混凝土强度试验检测记录（回弹法）-详情
     */
    @Override
    public ReportHntjgHntqdhtfjlbBaDetailVo queryById(Long detailId){
        return baseMapper.selectVoById(detailId);
    }

    /**
     * 查询混凝土强度试验检测记录（回弹法）-详情列表
     */
    @Override
    public TableDataInfo<ReportHntjgHntqdhtfjlbBaDetailVo> queryPageList(ReportHntjgHntqdhtfjlbBaDetailBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportHntjgHntqdhtfjlbBaDetail> lqw = buildQueryWrapper(bo);
        Page<ReportHntjgHntqdhtfjlbBaDetailVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询混凝土强度试验检测记录（回弹法）-详情列表
     */
    @Override
    public List<ReportHntjgHntqdhtfjlbBaDetailVo> queryList(ReportHntjgHntqdhtfjlbBaDetailBo bo) {
        LambdaQueryWrapper<ReportHntjgHntqdhtfjlbBaDetail> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportHntjgHntqdhtfjlbBaDetail> buildQueryWrapper(ReportHntjgHntqdhtfjlbBaDetailBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportHntjgHntqdhtfjlbBaDetail> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getExcelId() != null, ReportHntjgHntqdhtfjlbBaDetail::getExcelId, bo.getExcelId());
        lqw.eq(StringUtils.isNotBlank(bo.getLingq()), ReportHntjgHntqdhtfjlbBaDetail::getLingq, bo.getLingq());
        lqw.eq(StringUtils.isNotBlank(bo.getQiangddj()), ReportHntjgHntqdhtfjlbBaDetail::getQiangddj, bo.getQiangddj());
        lqw.eq(StringUtils.isNotBlank(bo.getLeix()), ReportHntjgHntqdhtfjlbBaDetail::getLeix, bo.getLeix());
        lqw.eq(StringUtils.isNotBlank(bo.getZhengszh()), ReportHntjgHntqdhtfjlbBaDetail::getZhengszh, bo.getZhengszh());
        lqw.eq(StringUtils.isNotBlank(bo.getLvdz()), ReportHntjgHntqdhtfjlbBaDetail::getLvdz, bo.getLvdz());
        lqw.eq(StringUtils.isNotBlank(bo.getJiaozrq()), ReportHntjgHntqdhtfjlbBaDetail::getJiaozrq, bo.getJiaozrq());
        lqw.eq(StringUtils.isNotBlank(bo.getHuitzPjz()), ReportHntjgHntqdhtfjlbBaDetail::getHuitzPjz, bo.getHuitzPjz());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuangt()), ReportHntjgHntqdhtfjlbBaDetail::getZhuangt, bo.getZhuangt());
        lqw.eq(StringUtils.isNotBlank(bo.getJioad()), ReportHntjgHntqdhtfjlbBaDetail::getJioad, bo.getJioad());
        lqw.eq(StringUtils.isNotBlank(bo.getShend()), ReportHntjgHntqdhtfjlbBaDetail::getShend, bo.getShend());
        lqw.eq(StringUtils.isNotBlank(bo.getBianh()), ReportHntjgHntqdhtfjlbBaDetail::getBianh, bo.getBianh());
        lqw.eq(StringUtils.isNotBlank(bo.getWeiz()), ReportHntjgHntqdhtfjlbBaDetail::getWeiz, bo.getWeiz());
        lqw.eq(bo.getShiczRi1() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi1, bo.getShiczRi1());
        lqw.eq(bo.getShiczRi2() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi2, bo.getShiczRi2());
        lqw.eq(bo.getShiczRi3() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi3, bo.getShiczRi3());
        lqw.eq(bo.getShiczRi4() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi4, bo.getShiczRi4());
        lqw.eq(bo.getShiczRi5() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi5, bo.getShiczRi5());
        lqw.eq(bo.getShiczRi6() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi6, bo.getShiczRi6());
        lqw.eq(bo.getShiczRi7() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi7, bo.getShiczRi7());
        lqw.eq(bo.getShiczRi8() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi8, bo.getShiczRi8());
        lqw.eq(bo.getShiczRi9() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi9, bo.getShiczRi9());
        lqw.eq(bo.getShiczRi10() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi10, bo.getShiczRi10());
        lqw.eq(bo.getShiczRi11() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi11, bo.getShiczRi11());
        lqw.eq(bo.getShiczRi12() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi12, bo.getShiczRi12());
        lqw.eq(bo.getShiczRi13() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi13, bo.getShiczRi13());
        lqw.eq(bo.getShiczRi14() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi14, bo.getShiczRi14());
        lqw.eq(bo.getShiczRi15() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi15, bo.getShiczRi15());
        lqw.eq(bo.getShiczRi16() != null, ReportHntjgHntqdhtfjlbBaDetail::getShiczRi16, bo.getShiczRi16());
        return lqw;
    }

    /**
     * 新增混凝土强度试验检测记录（回弹法）-详情
     */
    @Override
    public Boolean insertByBo(ReportHntjgHntqdhtfjlbBaDetailBo bo) {
        ReportHntjgHntqdhtfjlbBaDetail add = BeanUtil.toBean(bo, ReportHntjgHntqdhtfjlbBaDetail.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setDetailId(add.getDetailId());
        }
        return flag;
    }

    /**
     * 修改混凝土强度试验检测记录（回弹法）-详情
     */
    @Override
    public Boolean updateByBo(ReportHntjgHntqdhtfjlbBaDetailBo bo) {
        ReportHntjgHntqdhtfjlbBaDetail update = BeanUtil.toBean(bo, ReportHntjgHntqdhtfjlbBaDetail.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportHntjgHntqdhtfjlbBaDetail entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除混凝土强度试验检测记录（回弹法）-详情
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
